package com.hippo4j.plugin.impl;

import com.hippo4j.plugin.RejectAwarePlugin;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;

@Slf4j
public class TaskRejectCountRecordPlugin implements RejectAwarePlugin {

    public static final String PLUGIN_NAME = "task-reject-count-record-plugin";

    private AtomicInteger count = new AtomicInteger(0);

    @Override
    public String getPluginId() {
        return PLUGIN_NAME;
    }

    @Override
    public void beforeReject(Runnable r, ThreadPoolExecutor executor) {
        count.addAndGet(1);
        log.info(r.toString() + " 被拒绝了");
    }
}
